using System.Net.Mail;
using System.Text;
using Headspring.Training.Domain;
using Headspring.Training.Domain.Services;
using StructureMap;
using MailMessage=System.Net.Mail.MailMessage;

namespace Headspring.Training.WebUI.Services.Impl
{
	[Pluggable(Keys.DEFAULT)]
    public class EmailSender : IEmailSender
    {

        private ISmtpSender _sender;


        public EmailSender(ISmtpSender sender)
        {
            _sender = sender;
        }

        public void Send(WorkOrderNotification notification)
        {
            // pull the relevant data from the notification and comprise a message to be sent via email
            StringBuilder sb = new StringBuilder();
            sb.Append("Your work order, number ").Append(notification.WorkOrder.Number).Append(
                ", has changed status.");
            sb.Append("Work order has changed from ").Append(notification.PreviousStatus.FriendlyName).Append(" to ").Append
                (notification.WorkOrder.FriendlyStatus);
            string emailSubj = "FYI: Work order status has CHANGED...";
            MailMessage mailObj = new MailMessage(notification.From.EmailAddress, notification.Recipient.EmailAddress, emailSubj, sb.ToString());
            _sender.Send(mailObj);
        }
    }
}